package com.alibaba.citrus.cr.platform.enhance.functions.diff.activity.router;

import java.util.Map;

import javax.annotation.Resource;

import com.alibaba.citrus.cr.platform.enhance.facade.service.diff.common.DiffCheckRequest;
import com.alibaba.citrus.cr.platform.enhance.functions.diff.common.constant.DiffStrategyRouteDict;
import com.alibaba.citrus.cr.platform.enhance.functions.diff.common.constant.SalesOrderLineDiffStandardFieldDict;
import com.alibaba.citrus.cr.platform.enhance.functions.diff.common.router.DiffCheckProcessor;
import com.alibaba.citrus.cr.platform.enhance.functions.diff.common.template.OneDiffOneTemplate;
import com.alibaba.citrus.cr.platform.enhance.repository.model.diff.common.FieldLineDTO;
import com.alibaba.cz.base.tool.log.Log;
import com.alibaba.lattice2.epoch.sdk.model.Result;

import com.epoch.app.bcorder.service.BaseDataService;
import com.epoch.app.bcorder.service.UnifiedInventoryService;
import com.epoch.app.crpricecenter.propertyprocess.service.PropertyProcessService;
import com.ql.util.express.ExpressRunner;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

/**
 * @author: hanguo
 * @create: 2022/01/25
 * @Description sap006子单（基准）和 销售子单 之间的对账
 */
@Component
public class Sap006SDODetailDiffSalesOrderProcessor extends DiffCheckProcessor {

    private Log log = Log.getLogger(Sap006SDODetailDiffSalesOrderProcessor.class);

    /**
     * 规则表达式引擎
     */
    @Resource
    private  ExpressRunner expressRunner;

    @Resource
    private OneDiffOneTemplate oneDiffOneTemplate;


    @Resource
    private PropertyProcessService propertyProcessService;


    @Resource
    private BaseDataService baseDataService;

    @Resource
    private UnifiedInventoryService unifiedInventoryService;

    @Override
    public String obtainStrategyRoute() {
        return DiffStrategyRouteDict.SAP006DETAIL_DIFF_SALES_ORDER_LINE.getStrategyCode();
    }

    @Override
    public Result<String> diff(DiffCheckRequest diffCheckRequest) {

        Map<String, FieldLineDTO> baseLineDataMap = diffCheckRequest.getBaseLineDataMap();
        FieldLineDTO outOrderIdDTO = baseLineDataMap.get(SalesOrderLineDiffStandardFieldDict.SAP_SALES_ORDER_LINE_ID.getFieldCode());
        String outOrderIdValue = outOrderIdDTO.getFieldValue();
        if(StringUtils.isNotBlank(outOrderIdValue)){
            outOrderIdDTO = FieldLineDTO.of("outerItemKey", SalesOrderLineDiffStandardFieldDict.SAP_SALES_ORDER_LINE_ID.getFieldCode(), outOrderIdValue.trim());
            baseLineDataMap.put(SalesOrderLineDiffStandardFieldDict.UNIT_PRICE.SAP_SALES_ORDER_LINE_ID.getFieldCode(), outOrderIdDTO);
        }
        return super.diff(diffCheckRequest, oneDiffOneTemplate);
    }

}
